<template>
	<view>

		<form @submit="" @reset="">
			<view style="margin: 10px;">
				<view class="cu-form-group ">
					<view class="title">币种选择</view>
					<picker @change="PickerChange" :value="type" :range="picker">
						<view class="picker">
							{{type}}
						</view>
					</picker>
				</view>
			</view>


			<view style="margin: 10px;">
				<view class="cu-form-group t-t1">
					<view class="title">转账账号</view>

				</view>
				<view class="cu-form-group ">
					<input type="text" placeholder="请输入收款人手机号" v-model="form.mobile" @tap="chight"></input>
				</view>
			</view>

			<view style="margin: 10px;">
				<view class="cu-form-group t-t1">
					<view class="title">转账数量</view>

				</view>
				<view class="cu-form-group ">

					<input type="number" placeholder="请输入转账数量" v-model="form.number" @tap="chight"></input>
					<text class="text-gray margin-right-sm">￥</text>
					<text @tap="allin">{{i18n.cash.allin}}</text>
				</view>
				<view class="line"></view>
				<view class="cu-form-group t-t2">
					<view class="">
						<text class="text-gray margin-right-sm">{{i18n.cash.available}}</text>
						<text class="text-yellow margin-right-sm">{{type1_use}}</text>
						<!-- <text class="text-white margin-right-sm">USDT</text> -->
					</view>
				</view>
			</view>
			<!-- <view class="cu-form-group">
				<view class="title">提币备注</view>
				<input placeholder="选填" name="input"></input>
			</view> -->
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-yellow lg" @tap="submit">{{i18n.cash.confirm}}</button>
			</view>
		</form>
		<key-words :show_key="show_key" :show_subTitle="false" :price="'1.0012'" @closeFuc="closeFuc" @getPassword="getPassword"></key-words>
	</view>

</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				// picker: ['BTC', 'ETH', 'EMP'],
				type: '',
				form: {
					number: '',
					mobile: '',
					ptype1: ''
				},
				inc: false,
				show_key: false,
				check: false,
			}
		},
		computed: {
			...mapState({
				userinfo: state => state.user.userinfo,
				myconfig: state => state.user.myconfig
			}),
			hasLogin() {
				return this.userinfo.id ? true : false
			},
			rule() {
				return this.myconfig.user2user;
			},
			cointype2() {
				return this.myconfig.cointype2;
			},
			picker() {
				let arr = [];
				for (let key in this.rule) {
					arr.push(key)
				}
				return arr;
			},
			type1_use() {
				return this.userinfo[this.rule[this.type]];
			},

			type1_freeze() {
				return this.userinfo[this.rule[this.type] + 'freeze'];
			},

			type1_total() {
				let wall = this.rule[this.type];
				return this.accAdd(this.userinfo[wall], this.userinfo[wall + 'freeze'])
			},
			i18n() {
				return this.$t('message');
			},

		},
		methods: {
			...mapActions(['getUserinfo']),
			PickerChange(e) {
				this.type = this.picker[e.detail.value];
				this.form.ptype1 = this.cointype2[this.type];
			},
			//加法
			accAdd(arg1, arg2) {
				var r1, r2, m, n;
				try {
					r1 = arg1.toString().split(".")[1].length
				} catch (e) {
					r1 = 0
				}
				try {
					r2 = arg2.toString().split(".")[1].length
				} catch (e) {
					r2 = 0
				}
				m = Math.pow(10, Math.max(r1, r2));
				//last modify by deeka
				//动态控制精度长度
				n = (r1 >= r2) ? r1 : r2;
				var ree = ((arg1 * m + arg2 * m) / m).toFixed(n);
				return ree > 0 ? ree : 0;
			},
			submit() {
				if (!this.check) {
					this.show_key = true;
					return 1;
				}
				this.$http.post('Transfer.user2user', this.form).then(res => {
					this.$api.msg(`转账成功`);
					this.getUserinfo()
					setTimeout(() => {
						this.$api.prePage()
					}, 800)
				})
			},
			chight() {
				this.inc = true;
			},
			lost() {
				this.inc = false;
			},
			closeFuc() {
				this.show_key = false;
			},
			allin() {
				this.form.number = this.type1_use
			},
			//密码输入完需要执行的方法
			getPassword(msg) {
				//msg:密码   例如:{msg:123456}
				console.log(msg)
				let data = {
					password2: msg.password
				}
				this.$http.post('user.checkpass', data).then(res => {
					console.log(res)
					if (res.code == 1) {
						this.check = true;
						this.submit();
					} else {
						this.$api.msg(res.msg);
					}
				})
				this.closeFuc();
			},
		},
		onShow() {
			this.getUserinfo()
			this.type = this.picker[0];
			this.form.ptype1 = this.cointype2[this.type];
		},
	}
</script>

<style>
	.row {
		display: inline;
	}

	.tij {
		bottom: 0px;

		width: -webkit-fill-available;
	}
</style>
